package farm.pattern.observer;

import farm.entity.EnvironmentData;

import java.util.ArrayList;
import java.util.List;

public class EnvironmentMonitor implements Subject {
    private List<Observer> observers = new ArrayList<>();
    private EnvironmentData data = new EnvironmentData();

    @Override
    public void addObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers() {
        observers.forEach(o -> o.update(data));
    }

    public void updateData(EnvironmentData newData) {
        data = newData;
        notifyObservers();
    }
}